package com.gen.jpa.entity;

import com.gen.jpa.base.MySqlDataTypeEnum;
import lombok.*;

/**
 * 表格列模型
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ColumnModel {
    /**
     * 列名
     */
    private String columnName;
    /**
     * 驼峰列名
     */
    private String humpColumnName;
    /**
     * 列类型
     */
    private String columnType;
    /**
     * Java类型
     */
    @Setter(AccessLevel.NONE)
    private String javaType;
    /**
     * 列描述
     */
    private String columnDesc;
    /**
     * 是否主键
     */
    private boolean isPrimary;

    /**
     * 列类型转Java类型
     * @param dataType
     */
    public void setJavaType(String dataType) {
        MySqlDataTypeEnum mySqlDataTypeEnum = MySqlDataTypeEnum.getEnum(dataType.toUpperCase());
        if(mySqlDataTypeEnum!=null){
        switch (mySqlDataTypeEnum) {
            case INT:
                this.javaType = "Integer";
                break;
            case BIT:
                this.javaType = "Boolean";
                break;
            case TINYINT:
            case   SMALLINT:
                this.javaType = "Integer";
                break;
            case BIGINT:
                this.javaType = "Long";
                break;
            case DECIMAL:
                this.javaType = "BigDecimal";
                break;
            case DOUBLE:
                this.javaType = "Float";
                break;
            case FLOAT:
                this.javaType = "Double";
                break;
            case DATE:
            case DATETIME:
                this.javaType = "Date";
                break;
            case TIME:
                this.javaType = "Time";
                break;
            case TIMESTAMP:
                this.javaType = "Timestamp";
                break;
            case CHAR:
            case VARCHAR:
            case JSON:
            case TEXT:
            case BLOB:
                this.javaType = "String";
                break;
            default:
                this.javaType = dataType;
                break;
        }
        }
    }
}